package com.example.shop.fgo.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.example.shop.fgo.Constant;
import com.example.shop.fgo.R;
import com.example.shop.fgo.ui.fragment.WPFragment;

/**
 * Created by Administrator on 2017/2/10.
 * 
 * 

 */

public class DigSort extends Dialog implements View.OnClickListener {
    private FrameLayout mTvSortA;
    private FrameLayout mTvSortZ;
    private FrameLayout mTvSortNew;
    private FrameLayout mTvSortOld;
    private Button mBtCancel;
    private WPFragment mWPFragment;
    private ImageView mImageViewSelected;
    private FrameLayout mFrameLayout上一个选中的;
    public DigSort(final Context context, WPFragment wpFragment) {
        super(context);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mWPFragment=wpFragment;
        setContentView(R.layout.dig_sort);
    

        mTvSortA = (FrameLayout) findViewById(R.id.tv_sort_a);
        mTvSortZ = (FrameLayout) findViewById(R.id.tv_sort_z);
        mTvSortNew = (FrameLayout) findViewById(R.id.tv_sort_new);
        mTvSortOld = (FrameLayout) findViewById(R.id.tv_sort_old);
        mBtCancel = (Button) findViewById(R.id.bt_cancel);
        
        mImageViewSelected= (ImageView) LayoutInflater.from(context).inflate(R.layout.sort_selected,mTvSortA,false);
        
        mBtCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancel();
        
            }
        });
    
        mTvSortA.setOnClickListener(this);
        mTvSortZ.setOnClickListener(this);
        mTvSortNew.setOnClickListener(this);
        mTvSortOld.setOnClickListener(this);
        
    }
    
    @Override
    public void onClick(View v) {
        String o=null;
        String asc=null;
        if (mFrameLayout上一个选中的 != null) {
            mFrameLayout上一个选中的.removeView(mImageViewSelected);
        }
    
        /* A-Z  Constant.SORT_FILE_NAME   1
                * Z-A  Constant.SORT_FILE_NAME   0
                *
        *
        * 从新到旧 Constant.SORT_USER_PTIME  0
                * 从旧到新 Constant.SORT_USER_PTIME  1
                * */
        switch (v.getId()){
            case R.id.tv_sort_a:
                mTvSortA.addView(mImageViewSelected);
                o= Constant.SORT_FILE_NAME;
                asc="1";
                break;
            case R.id.tv_sort_z:
                mTvSortZ.addView(mImageViewSelected);
                o= Constant.SORT_FILE_NAME;
                asc="0";
                break;
            case R.id.tv_sort_new:
                mTvSortNew.addView(mImageViewSelected);
                o= Constant.SORT_USER_PTIME;
                asc="0";
                break;
            case R.id.tv_sort_old:
                mTvSortOld.addView(mImageViewSelected);
                o= Constant.SORT_USER_PTIME;
                asc="1";
                break;
            
        }

        mFrameLayout上一个选中的= (FrameLayout) v;
        mWPFragment.changeSortParams(o,asc);
        cancel();
        
      
    }
}
